<template>
  <div class="login-container">
<!--    <div class="log">-->
<!--      <div class="log_img">-->
<!--      </div>-->
<!--      <div class="log_title">-->
<!--        <div class="title_text">-->
<!--          <span>欢迎来到</span><br>-->
<!--          管理后台-->
<!--        </div>-->
<!--      </div>-->
<!--    </div>-->
    <div  class="bg-img"></div>
    <div class="login">

      <div class="title_text">
        账号密码登录
        <div class="line"></div>
      </div>
      <el-form ref="loginForm" :model="loginForm" auto-complete="on" label-position="left">
        <el-form-item prop="username">
          <el-col>
            <el-input
              ref="username"
              v-model="loginForm.phone"
              placeholder="请输入手机号"
              name="username"
              type="text"
              tabindex="1"
            />
          </el-col>

        </el-form-item>

        <el-form-item prop="password">
          <el-input
            :key="passwordType"
            ref="password"
            v-model="loginForm.password"
            :type="passwordType"
            placeholder="请输入密码"
            name="password"
            tabindex="2"
            @keyup.enter.native="handleLogin"
          />
          <span class="show-pwd" @click="showPwd">
          <svg-icon :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'" />
        </span>
        </el-form-item>

        <el-col :span="24">
          <el-button :loading="loading" type="primary" class="loginBtn" @click="handleLogin">登录</el-button>
        </el-col>


        <!-- <div class="tips">
          <span style="margin-right:20px;">username: admin</span>
          <span> password: any</span>
        </div> -->

      </el-form>
    </div>
<!--    <div class="number">鄂ICP备2021021536号</div>-->
  </div>
</template>

<script>
import { validUsername } from '@/utils/validate'
import {thisUser, userLogin,routerGroupCurrentManager} from "@/api/index";
import { setToken } from "@/utils/auth";
import path from "path";
// import {permissionList} from "@/api/user";
export default {
  name: 'Login',
  data() {
    return {
      loginForm: {
        phone: '18256477901',
        password: 'admin'
      },
      // loginRules: {
      //   username: [{ required: true, trigger: 'blur', validator: validateUsername }],
      //   password: [{ required: true, trigger: 'blur', validator: validatePassword }]
      // },
      loading: false,
      passwordType: 'password',
      redirect: undefined
    }
  },
  watch: {
  },
  methods: {
    showPwd() {
      if (this.passwordType === 'password') {
        this.passwordType = ''
      } else {
        this.passwordType = 'password'
      }
      this.$nextTick(() => {
        this.$refs.password.focus()
      })
    },
     async handleLogin() {
      if(!this.loginForm.phone){
        this.$message({
          message: '请输入手机号',
          type: 'warning'
        });
        return;
      }
      if(!this.loginForm.password){
        this.$message({
          message: '请输入密码',
          type: 'warning'
        });
        return;
      }
       const res=await userLogin({
         phone: this.loginForm.phone,
         password: this.loginForm.password,
       })
       // console.log(res)
       if(res.code==10000){
         setToken(res.data.token);
        //  this.$router.push({name :'Order'} )
         this.getList()

       }
     },

    async getList(){
      routerGroupCurrentManager({}).then(res=>{
        // console.log(res)
        if(res.code==10000){
          if(res.data.menu.length < 1){
            this.$message({
              message: '暂无权限',
              type: 'error'
            });
          }else{
            // console.log(res.data)
            // this.$router.push({name :res.data.menu[0].router_name} )
            this.$router.push({path :'/'+res.data.menu[0].router_name+'/'+res.data.menu[0].router_name} )
          }
        }
      })
    },

  }
}
</script>

<style lang="scss">
/* 修复input 背景不协调 和光标变色 */
/* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */

$bg:#283443;
$light_gray:#fff;
$cursor: #fff;


@supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
  .login-container .el-input input {
    color: $cursor;
  }
}

/* reset element-ui css */
.login-container {
  position: relative;
  .log{
    .log_img{
      width: 500px;
      height: 500px;
      //margin: 115px 0 0 130px;
      img{
        width: 100%;
      }
    }
    .log_title{
      margin-top: 60px;
      .title_text{
        margin-left: 240px;
        color: #fff;
        font-size: 42px;
        font-family: PingFangSC-Regular, PingFang SC;
        line-height: 60px;
        span{
          font-size: 72px;
          line-height: 100px;
        }
      }
    }
  }
  .login{
    width: 594px;
    background: rgba(255,255,255,.6);
    position: absolute;
    //top: 220px;
    top: 60%;
    left: 208px;
    border-radius: 12px;
    padding:50px;
    box-sizing: border-box;
    transform: translateY(-50%);
    .title_text{

      margin-bottom: 98px;
      font-size: 40px;
      font-family: PingFangSC-Semibold, PingFang SC;
      font-weight: 600;
      color: #333333;
      line-height: 70px;
      letter-spacing: 1px;
      .line{
        width: 100px;
        height: 5px;
        background: #70C3D3;
        margin-top: 10px;
      }
      //text-align: right;
    }
    .loginin{
      font-size: 31px;
      font-family: PingFangSC-Semibold, PingFang SC;
      font-weight: 600;
      color: rgba(0,0,0,0.3);
      line-height: 44px;
      //text-align: right;
    }
    .el-form-item__label{
      color: #333;
    }
    .el-form-item {
      //position: absolute;
      //right: 0;
      width:100%;
      height: 100px;
      margin-bottom: 45px;
      .el-input {
        width: 100%;
        height: 100px;
        display: inline-block;
        input{
          width: 100%;
          border-radius: 50px;
          height: 100%;
          background: rgba(255,255,255,.6);
          color: #000;
          font-size: 26px;
          padding: 32px 51px;
          //box-shadow: 4px 4px 1px rgba(12, 36, 128, 0.24);

        }
      }
    }

    .loginBtn{
      width: 100%;
      height: 90px;
      background: #70C3D3;
      border-radius: 45px;
      display: block;
      //margin:30px auto;
      font-size: 28px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #FFFFFF;
      line-height: 40px;
      letter-spacing: 1px;
      border: none;
      //position: absolute;
      //right: 0;
    }


  }



}
</style>

<style lang="scss" scoped>
.number{
  height: 20px;
  font-size: 14px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #AAAAAA;
  line-height: 20px;
  text-align: center;
  position: absolute;
  bottom: 10px;
  //display: flex;
  left:50%;
  transform: translateX(-50%);
}
$bg:#2d3a4b;
$dark_gray:#889aa4;
$light_gray:#eee;

.login-container {
  min-height: 100%;
  width: 100%;

  .bg-img{
    //src="/img/login_bg.png"
    //background:url('/login_bg.png') no-repeat;
    width: 100%;

    min-height: 100vh;
    background-size:cover;
    background-attachment:fixed;

  }
  background: #FAFAFA;
  overflow: hidden;

  //.login-form {
  //  position: relative;
  //  width: 520px;
  //  max-width: 100%;
  //  padding: 160px 35px 0;
  //  margin: 0 auto;
  //  overflow: hidden;
  //}

  .tips {
    font-size: 14px;
    color: #fff;
    margin-bottom: 10px;

    span {
      &:first-of-type {
        margin-right: 16px;
      }
    }
  }

  .svg-container {
    padding: 6px 5px 6px 15px;
    color: $dark_gray;
    vertical-align: middle;
    width: 30px;
    display: inline-block;
  }

  .title-container {
    position: relative;

    .title {
      font-size: 26px;
      color: $light_gray;
      margin: 0px auto 40px auto;
      text-align: center;
      font-weight: bold;
    }
  }
  .show-pwd {
    position: absolute;
    right: 60px;
    //top: 7px;
    top: 50%;
    transform: translateY(-50%);

    font-size: 16px;
    color: $dark_gray;
    cursor: pointer;
    user-select: none;
  }

}
</style>
<style scoped lang="less">
/deep/.el-input input{
  color: #000000;
  &::placeholder {
    color: #000000;
  }
}
</style>
